package com.shioirikukuri.web.controller;

import com.shioirikukuri.common.web.Result;
import com.shioirikukuri.config.AlipayProperties;
import com.shioirikukuri.domain.PayVo;
import com.shioirikukuri.domain.RefundVo;
import com.shioirikukuri.service.IAlipauService;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * Created by shioirikukuri
 */
@RestController
@RequestMapping("/alipay")
public class AlipayController {
    @Autowired
    private AlipayClient alipayClient;
    @Autowired
    private AlipayProperties alipayProperties;
    @Autowired
    private IAlipauService alipayService;

    @RequestMapping("/pay")
    public Result<String> pay(@RequestBody  PayVo vo) throws AlipayApiException {
        String html = alipayService.pay(vo);
        return Result.success(html);
    }

    @RequestMapping("/rsaCheckV1")
    public Result<Boolean> rsaCheckV1(@RequestParam Map<String, String> params) throws AlipayApiException {
        Boolean signVerified = alipayService.rsaCheckV1(params);

        return Result.success(signVerified);
    }

    @RequestMapping("/refund")
    public Result<Boolean> refund(@RequestBody RefundVo vo) throws AlipayApiException {
        Boolean successFlag = alipayService.refund(vo);
        return Result.success(successFlag);
    }
}
